//
//  GaoDefaultNoDataView.m
//  DuTe
//
//  Created by Gikki Ares on 2021/1/4.
//  Copyright © 2021 vgemv. All rights reserved.
//

#import "JsNoDataView.h"
#import "JsGeometryManager.h"
#import "JsBundleManager.h"
@interface JsNoDataView()
{
	JsButtonLiiOne * mButton_noData;
}

@end


@implementation JsNoDataView


- (instancetype)init {
	if(self = [super init]) {
		[self setupUi];
	}
	return self;
}

	//完全构造函数
//vm的frame只是自身frame的复制.
- (instancetype)initWithFrame:(CGRect)frame {
	if(self = [super initWithFrame:frame]) {
		[self setupUi];
	}
	return  self;
}

/*
 1,默认样式 图片为100*100
 2,image_spacingV_label = 10
 3,labelHeight = 40,固定值,提示语句两行就可以了.
 4,总大小为200,240
 */

- (void)setupUi {
	if(!mButton_noData) {
		mButton_noData = [JsButtonLiiOne new];
		[self addSubview:mButton_noData];
	}
	CGRect buttonFrame = [JsGeometryManager frameAlignCenterWithContainerSize:self.frame.size size:CGSizeMake(200, 140)];
	mButton_noData.frame = buttonFrame;
	mButton_noData.imageView.contentMode = UIViewContentModeScaleAspectFit;
	mButton_noData.label.numberOfLines = 2;
	JsButtonLiiVm * vm = mButton_noData.vm;
	vm.labelFont = [UIFont systemFontOfSize:16];
	vm.text = [self noDataMessage];
	vm.foregroundImage = [self noDataIamge];
	vm.labelTextColor = [UIColor blackColor];
	vm.foregroundImageViewFrame = [JsGeometryManager frameHAlignCenterVAlignTopWithContainerSize:buttonFrame.size size:CGSizeMake(100, 100)];
	vm.labelFrame = [JsGeometryManager frameHAlignCenterVBelowWithContainerSize:buttonFrame.size size:CGSizeMake(200, 40) siblingFrame:vm.foregroundImageViewFrame offset:CGPointMake(0, 10)];
	[mButton_noData setupUi];
	
}

- (void)layoutSubviews {
	[super layoutSubviews];
	[self setupUi];
}

- (UIImage *)noDataIamge {
	if(!_mimage) {
		UIImage * defaultNoDataImage = [UIImage imageNamed:@"EmptyBox_Black.png" inBundle:[JsBundleManager jsUtilityBundle] compatibleWithTraitCollection:nil];
		return defaultNoDataImage;
	}
	return _mimage;
}

-(NSString *)noDataMessage {
	if(!_mstr_title) {
		return @"亲,数据为空哦";
	}
	return _mstr_title;
}


- (instancetype)initWithImage:(UIImage *)image title:(NSString *)title {
	if(self = [super init]) {
		JsButtonLiiOne * button = [[JsButtonLiiOne alloc] initWithFrame:CGRectMake(0, 0, 160, 180)];
		_mimage = image;
		[button setTitle:title];
		[self addSubview:button];
	}
	return self;
}

- (void)updateUi {
	[self setupUi];
}

@end
